import "./index.css";
import Title from "antd/es/typography/Title";
import { Divider, Flex, message } from "antd";
import { listQuestionBankVoByPageUsingPost } from "@/api/questionBankController";
import { listQuestionVoByPageUsingPost } from "@/api/questionController";
import QuestionBankList from "@/components/QuestionBankList";
import QuestionTable from "@/components/QuestionTable";

// 本页面使用服务端渲染，禁用静态生成
export const dynamic = "force-dynamic";

export default async function HomePage() {
  let questionBankList = [];
  let questionList = [];
  let total;

  // 获取题库列表
  try {
    const res = await listQuestionBankVoByPageUsingPost({
      pageSize: 20,
      sortField: "createTime",
      sortOrder: "desc",
    });
    questionBankList = res?.data?.records || [];
  } catch (e) {}

  // 获取题目列表
  try {
    const res = await listQuestionVoByPageUsingPost({
      pageSize: 20,
      sortField: "createTime",
      sortOrder: "desc",
    });
    questionList = res?.data?.records || [];
    total = res?.data?.total;
  } catch (e) {}

  return (
    <div id={"homePage"} className={"limit-width"}>
      <Flex vertical>
        <Flex>
          <Title level={3}>面试题库</Title>
        </Flex>
        <QuestionBankList questionBankList={questionBankList} />
      </Flex>
      <Divider />
      <Flex vertical>
        <Flex>
          <Title level={3}>面试题目</Title>
        </Flex>
        <QuestionTable
          defaultQuestionList={questionList}
          defaultTotal={total}
        />
      </Flex>
    </div>
  );
}
